<?php
// 读取客户端表单数据
$ename = $_REQUEST['ename'];
$gender = $_REQUEST['gender'];
$birthday = $_REQUEST['birthday'];
$salary = $_REQUEST['salary'];
$isMarried = $_REQUEST['isMarried'];
$deptNo = $_REQUEST['deptNo'];

// 链接数据库，执行Insert语句
$sql = "INSERT INTO
emp(ename,gender,borthday,salary,isMarried,deptNo)
VALUES('$ename','$gender','$birthday','$salary','$isMarried','$deptNo')";
// echo $sql;
$conn = mysqli_connect('127.0.0.1','root','','toma');
mysqli_query($conn,'SET NAMES UTF8'); // 告诉数据库编码方式
$result = mysqli_query($conn,$sql);

// 根据提交的结果，给客户端以提示
$msg = '';
if($result){
  $msg='添加记录成功！新增员工的自增编号为：'.mysqli_insert_id($conn);
}else{
  $msg='添加记录失败！错误编号：'.mysqli_errno($conn);
}

 ?>
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>基于MySql的CRUD</title>
</head>
<body>
  <h2>新添员工的执行结果</h2>
  <h3><?php echo $msg ?></h3>
  <a href="ic.html">返回主菜单</a>
  <a href="1-addemp.html">继续添加</a>
</body>
</html>
